package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.entity.user.AuthContextUtil;
import com.atguigu.spzx.model.entity.user.UserInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.product.service.CategoryService;
import com.atguigu.spzx.product.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Mahone
 */
@Tag(name = "首页接口管理")
@RestController
@RequestMapping("/api/product")
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;

    @Operation(summary = "获取首页数据")
    @GetMapping("/index")
    public Result<IndexVo> index(){
        UserInfo userInfo = AuthContextUtil.getUserInfo();
        List<Category> categoryList = categoryService.selectAllOneData();
       List<ProductSku> productSkuList = productService.selectAllData();
       IndexVo indexVo = new IndexVo();
       indexVo.setCategoryList(categoryList);
       indexVo.setProductSkuList(productSkuList);
       return Result.ok(indexVo);
    }

}
